#!/usr/bin/perl -w

####################################################
# Copyright (c) 2002-2007 BioWare Corp.
# http://www.bigdaddymonitor.org
#
# This file is part of the BigDaddy Monitoring
# program. It is free software distributed under
# the terms of the BSD License. It is ditributed
# in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY; without event the implied
# warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# The BSD License is available from:
# http://www.opensource.org/licenses/bsd-license.php
####################################################

use IO::Socket;
use Net::Ping;


sub mod_port_tcp
{
    my ($server, $port_check) = @_;
    my $connected=0;
    my $fail=0;
    my $failCount;
    
    for (my $j=0; $j<6; $j++)
    {
        $fail=0;
    
        my $checkport = IO::Socket::INET->new(
            PeerAddr => "$server",
            PeerPort => $port_check,
            Proto => "tcp",
            Timeout => '1') or $fail = 1;
    
        if ($fail==1)
        {
            $failCount++;
        }
        else
        {
            $failCount=0;
        }
    }
    
    if ($failCount>3)
    {
        return "0";
    }
    else
    {
        return "1";
    }
    
    
}

sub mod_ping
{
    my ($server) = @_;
    my $count=0;
    my $bICMPAvail=0;
    my $bTCPAvail=0;
    
    #Check ICMP Proto
    my $p = Net::Ping->new("icmp");
    
    for (my $j=0; $j<5; $j++)
    {
        if (!$p->ping($server, 5))
        {
            $count++;
        }
    }
    
    if ($count>3)
    {
        $bICMPAvail=0;
    }
    else
    {
        $bICMPAvail=1;
    }
    
    
    if ($bICMPAvail==1)
    {
        return "1";
    }
    else
    {
        return "0";
    }

}

1;

